<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>用户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="resources/css/public.css" media="all"/>
</head>
<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    用户ID： <input type="text" class="layui-input idVal" placeholder="请输入用户ID"/>
                </div>
                <div class="layui-input-inline" >
                    用户姓名： <input type="text" class="layui-input nameVal" placeholder="请输入用户姓名"/>
                </div>
                <div class="layui-input-inline">
                    用户账号： <input type="text" class="layui-input telVal" placeholder="请输入用户账号"/>
                </div>
                <div class="layui-input-inline" >
                    用户性别： <input type="text" class="layui-input sexVal" placeholder="请输入用户性别"/>
                </div>
                <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>
        </form>
    </blockquote>
    <table id="tpUserTable" lay-filter="tpUserTable">
    </table>
    <!--操作-->
    <script type="text/html" id="statusTpl">
        <input type="checkbox" lay-skin="switch" name="status" lay-filter="status"  lay-event="update" lay-text="正常|锁定" {{ d.state == 0 ? "checked" : ""  }} >
    </script>
</form>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script type="text/javascript" th:inline="none">
    layui.use(['form', 'layer', 'table', 'laytpl'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table;
        //用户列表
        var tableIns = table.render({
            elem: '#tpUserTable',
            url: 'tpUserSelectByPage.do',
            cellMinWidth: 95,
            page: true,
            height: "full-200",
            limits: [10, 15, 20, 25],
            limit: 10,
            id: "tpUserTablezz",
            cols: [[
                {type: "checkbox", fixed: "left", width: 50},
                {field: 'perUserId', title: '用户ID', minWidth: 100, align: "center"},
                {field: 'perUserTel', title: '账号', minWidth: 100, align: "center"},
                {field: 'perUserPwd', title: '密码', minWidth: 100, align: "center"},
                {field: 'carNumber', title: '车牌号', minWidth: 100, align: "center",templet: '#zz'},
                {field: 'perUserName', title: '姓名', align: 'center'},
                {field: 'perUserSex', title: '性别', align: 'center'},
                {field: 'perUserAddress', title: '详细地址', align: 'center'},
                {field: 'perUserMoney', title: '账号余额', align: 'center'},
                {title: '状态', width: 260, field: 'state', fixed: "right", align: "center", templet: '#statusTpl'}
            ]]

        });

        //实现搜索功能
        $(".search_btn").click(function () {
            var perUserId = $(".idVal").val();
            var perUserName=$(".nameVal").val();
            var perUserTel=$(".telVal").val();
            var perUserSex=$(".sexVal").val();
            table.reload('tpUserTablezz', {
                where: {
                    perUserId:perUserId,
                    perUserName:perUserName,
                    perUserTel:perUserTel,
                    perUserSex:perUserSex,
                }
            });
        });

        table.on("tool(mUserTable)", function (obj) {
            //获取当前行的数据
            var data = obj.data;
            console.log(data);
            switch (obj.event) {
                case 'update':
                    updateState(data);
                    break;
            }
        });


        //更改方法
        function updateState(data) {
            console.log("cccc");
            var id=data.id;
            console.log(id);
            if (data.state==0)
            {
                var state=data.state+1;
                $.ajax({
                    url: "updateState.do",
                    data: {state: state,id:id},
                    type: "POST",
                    dataType: "json",
                    success: function (res) {
                        layer.msg("更改成功");
                    }
                });
            }else {
                var state=data.state-1;
                $.ajax({
                    url: "",
                    data: {state: state,id:id},
                    type: "POST",
                    dataType: "json",
                    success: function (res) {
                        layer.msg("更改成功");
                    }
                });
            }
        }


    });

</script>
<script id="zz" type="text/html">
    {{d.tperCar.perCarPlatenum}}
</script>
</body>
</html>